local weicheng = fk.CreateSkill {
  name = "lingling__weicheng",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__weicheng"] = "伪诚",
  [":lingling__weicheng"] = "锁定技，当其他角色对你使用【杀】时，若你上回合未对其使用【杀】，其须交给你一张牌否则无效。",

  ["#lingling__weicheng-ask"] = "伪诚：你须交给 %src 一张牌，否则此%arg无效",
}

weicheng:addEffect(fk.CardUsing, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(weicheng.name) and
      data.card.trueName == "slash" and table.contains(data.tos, player) then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      local turn_events = player.room.logic:getEventsByRule(GameEvent.Turn, 1, function (e)
        if turn_event == nil or e.id < turn_event.id then
          return e.data.who == player
        end
      end, 0)
      if #turn_events == 0 then
        return true
      else
        return #turn_events[1]:searchEvents(GameEvent.UseCard, 1, function (e)
          local use = e.data
          return use.from == player and use.card.trueName == "slash" and table.contains(use.tos, target)
        end) == 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target.dead or target:isNude() then
      data.nullifiedTargets = table.simpleClone(room.players)
    else
      local card = room:askToCards(data.from, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = weicheng.name,
        prompt = "#lingling__weicheng-ask:"..player.id.."::"..data.card:getTypeString(),
        cancelable = true,
      })
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, weicheng.name, nil, true, target)
      else
        data.nullifiedTargets = table.simpleClone(room.players)
      end
    end
  end,
})

return weicheng
